#include "common.h"
#include <stdint.h>

#ifdef __ERROR_ARRAY_DEFINITION__
	#define DEF_ERRMSG_BEGIN( CODE, BASE, ERRMSG )		\
		struct ErrMsgItem gErrorArray_UUID[]	= {	\
			{ CODE, #CODE ERRMSG},

	#define DEF_ERRMSG( CODE, ERRMSG )			\
			{ CODE, ERRMSG},
			
	#define DEF_ERRMSG_END					\
			{ _ERROR_CODE_MAX, "Max error code"}	\
		};
	#define SEGMENT_MASK -1
	const char * const Perror( int32_t errcode ){
		return gErrorArray_UUID[errcode & SEGMENT_MASK].description;
	}

	#include "error_code.lst"
	DEF_ERRMSG_END

	#undef DEF_ERRMSG_BEGIN
	#undef DEF_ERRMSG
	#undef DEF_ERRMSG_END
	#undef ERROR_ARRAY_DEFINITION

#else

	#ifndef __ERROR_ARRAY_DECLARE__
	#define __ERROR_ARRAY_DECLARE__
		struct ErrMsgItem{
			int32_t errcode;
			const char * description;
		};

		#define DEF_ERRMSG_BEGIN( CODE, BASE, ERRMSG )	\
			enum {					\
				CODE = BASE,

		#define DEF_ERRMSG( CODE, ERRMSG )		\
				CODE,
		
		#define DEF_ERRMSG_END 				\
				_ERROR_CODE_MAX			\
			};					\
			extern struct ErrMsgItem gErrorArray_UUID[]; 
		const char * const Perror( int32_t errcode ); 

		#include "error_code.lst"
		DEF_ERRMSG_END

		#undef DEF_ERRMSG_BEGIN
		#undef DEF_ERRMSG
		#undef DEF_ERRMSG_END
		#undef ERROR_ARRAY_DEFINITION
	#endif

#endif

